/**
 * Created by huangxuehua on 2017/12/6.
 */
//$("header>a.goBack").click(function(){
//    window.history.go(-1);
//})
var xpHome = new Vue({
    el:'#app',
    data:{
        imgBaseUrl:nUrls.imgBaseUrl,
        goodsList:[],//售后产品列表
        countNum:[],//产品总数
        countPrice:[],//合计金额
    },
    methods: {
        getImage:function(url){//加载图片  处理 url为空 加载出错
            if(url){
                return xpHome.imgBaseUrl+url;
            }
        },
        getDate:function(time){
            return nUtils.dateTime(time);
        },
        countMoneyFun:function(){//合计         一个订单一次计算
            for(var i = 0; i < xpHome.goodsList.length; i++){//循环订单
                xpHome.countPrice[i] = 0;
                xpHome.countNum[i] = 0;
                var temp=xpHome.goodsList[i];
                    xpHome.countPrice[i] += temp.shop_price * temp.goods_number;
                    xpHome.countNum[i] += parseInt(temp.goods_number)
                //console.log("6666"+xpHome.goodsList)
            }
        },
        getAfterSaleGoodsList:function() {
            var data = {
                "access_token": userInfo.access_token,
            }
            $.ajax({
                url:nUrls.getAfterSaleGoodsList,
                type:"POST",
                data:data,
                success: function (data) {
                    var result = eval('(' + data + ')');
                    if (result && result.code == 200) {
                        xpHome.goodsList=result.data;
                        xpHome.countMoneyFun();
                        //console.log("- xpHome.goodsList--", xpHome.goodsList)
                    }
                },
                error: function () {
                    console.log("添加到购物车出错");
                }
            })

        },
        getTypeAndColor:function(target,type){   //分割字符串
            var temp = "";
            if(target){
                var arr = target.split("-----");
                if(arr.length == 2){
                    if(type == 0){//颜色
                        return arr[1];
                    }else{//型号
                        return arr[0];
                    }
                }
            }
            return temp;
        },
       getAfterSaleType:function(order){
           var status = "";
           switch (order){
               case "0":
                   status = "维修";
                   break;
               case "1":
                   status = "换货";
                   break;
               case "2"://
                   status = "退货";
                   break;

           }
           return status;
       },
        AfterSaleStatus:function(idx){//根据 order 获取 订单状态名称
         window.location.href="./after_sale_type.html"
          window.localStorage.setItem("afterSaleGoodsInfo",JSON.stringify(xpHome.goodsList[idx]))
        },
        goGoodsDetail:function(id){
            window.location.href="../detail/goods_detail.html?id="+id;
        },
        goOnLine:function(){  //断网刷新
            nUtils.onLine();
        }

    }
});
$(function(){
    xpHome.getAfterSaleGoodsList()
})

